<template>
  <div class="trend-user-container">
    <el-row :gutter="30">
      <el-col :span="6">
        <div class="grid-content bg-cyan">
          <div class="wd-40 grid-left">
            <svg-icon icon="personnel" />
          </div>
          <div class="wd-60 grid-right">
            <div class="title">
              <div class="title-name">{{ $t('msg.profile.totalUserAmount') }}：</div>
              <div class="title-amount">
                <span ref="totalUserTarget">{{ data.totalUserAmount }}</span>
              </div>
            </div>
          </div>
        </div>
      </el-col>

      <el-col :span="6">
        <div class="grid-content bg-purple" style="background-color:#E6A23C">
          <div class="wd-40 grid-left">
            <User style="width: 3em; height: 3em" />
          </div>
          <div class="wd-60 grid-right">
            <div class="title">
              <div class="title-name">{{ $t('msg.profile.todayAddUserAmount') }}：</div>
              <div class="title-amount">
                <span ref="todayAddUserTarget">{{ data.todayAddUserAmount }}</span>
              </div>
            </div>
          </div>
        </div>
      </el-col>

      <el-col :span="6">
        <div class="grid-content bg-purple" style="background-color:#F56C6C">
          <div class="wd-40 grid-left">
            <svg-icon icon="eye" />
          </div>
          <div class="wd-60 grid-right">
            <div class="title">
              <div class="title-name">{{ $t('msg.profile.activeUserAmount') }}：</div>
              <div class="title-amount">
                <span ref="activeUserTarget">{{ data.activeUserAmount }}</span>
              </div>
            </div>
          </div>
        </div>
      </el-col>

      <el-col :span="6">
        <div class="grid-content bg-purple" style="background-color:#409EFF">
          <div class="wd-40 grid-left">
            <Money style="width: 3em; height: 3em" />
          </div>
          <div class="wd-60 grid-right">
            <div class="title">
              <div class="title-name">{{ $t('msg.profile.chargeAmount') }}：</div>
              <div class="title-amount">
                &yen; <span ref="chargeTarget">{{ data.chargeAmount }}</span>
              </div>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { CountUp } from 'countup.js'
import { defineProps, onMounted, ref } from 'vue'
import { Money, User } from '@element-plus/icons-vue'

const props = defineProps({
  data: {
    type: Object,
    required: true
  }
})

onMounted(() => {
  const options = {
    // 小数点位
    decimalPlaces: 0,
    // 持续时间
    duration: 1
  }
  // 用户总数
  new CountUp(totalUserTarget.value, props.data.totalUserAmount, options).start()
  // 新增注册
  new CountUp(todayAddUserTarget.value, props.data.todayAddUserAmount, options).start()
  // 活跃用户
  new CountUp(activeUserTarget.value, props.data.activeUserAmount, options).start()
  // 充值金额
  new CountUp(chargeTarget.value, props.data.chargeAmount, options).start()
})

const totalUserTarget = ref(null)
const todayAddUserTarget = ref(null)
const activeUserTarget = ref(null)
const chargeTarget = ref(null)
</script>

<style lang="scss" scoped>
.trend-user-container {
  .el-row {
    height: 40px;
    margin-bottom: 30px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .el-col {
    height: 40px;
    border-radius: 4px;
    text-align: center;
    vertical-align: middle;
    margin: auto;
    line-height: 20px;
  }
  .wd-40 { width: 40% }
  .wd-60 { width: 60% }
  .grid-left {float: left; margin-top: 10px;}
  .grid-right {float: right;}
  .bg-cyan {
    background: linear-gradient(to right, #67C23A, #63c432);
  }
  .grid-content {
    border-radius: 5px;
    height: 80px;
    font-weight: bold;
    border: 1px solid #d3dce6;
    padding: 4px;
    color: #fff;
  }
  .row-bg {
    padding: 10px 0;
    background-color: #f9fafc;
  }
  :deep(.svg-icon) {
    width: 3em !important;
    height: 3em !important;
    display: inline-block;
  }

  .title {
    padding: 12px 0px;
    .title-name {
      font-size: 16px;
      font-weight: bold;
    }
    .title-amount {
      font-size: 24px;
      margin-top: 6px;
    }
  }
}
</style>
